%% This file creates figure 1 in the main text
clear;

    [mpudta2,mputxt2] = xlsread('data\mpu_2day.xlsx');
    mpu = mpudta2(:,4);
    mpudts = datetime(mpudta2(:,3),mpudta2(:,2),mpudta2(:,1));
    
    all_data = array2timetable(mpu,'RowTimes',mpudts,'VariableNames',{'mpu',});
    
%-------------------------------------------------------------------------

%% Figure: Bar plot of change in mpu on FOMC meeting days

%% Dec 08, Aug  2011, Jul  1995, Oct 2008, Jan 2004
figure;
b = bar(all_data.mpu,.9); %all_data.Time,
set(b,'EdgeColor','black');
date_vec = datevec(all_data.Time) ;
date_label = date_vec(1:25:length(date_vec),1);
set(gca,'XTick',1:25:length(date_vec),'XTickLabel',date_label,'FontSize',12);
ylabel('Change in monetary policy uncertainty','FontSize',12);
set(gcf, 'PaperUnits', 'inches');
set(gcf, 'PaperSize', [7 5]);
set(gcf, 'PaperPositionMode', 'manual');
set(gcf, 'PaperPosition', [0 0 7 5]);
set(gcf, 'renderer', 'painters');

Kmax = 5;
Kmin = 10;
[maxKvals,maxKind] = maxk(all_data.mpu,Kmax);
%[maxKvals,maxKind] = maxk(alldataeff.pctmfiv_level,K);

[minKvals,minKind] = mink(all_data.mpu,Kmin);
%[minKvals,minKind] = mink(alldataeff.pctmfiv_level,K);

%maxtable = all_data(maxKind,{'mpu','monshk_daily'});
%mintable = all_data(minKind,{'mpu','monshk_daily'});
%mindind = 

text(minKind(1)-32,all_data.mpu(minKind(1))+.01,'Dec 2008 \rightarrow ','FontSize',10)
text(minKind(2)+1,all_data.mpu(minKind(2))+.01,'\leftarrow  Aug 2011 ','FontSize',10)
text(minKind(3)+1,all_data.mpu(minKind(3))-.01,'\leftarrow  Nov 1998 ','FontSize',10)
%text(minKind(4)-.01,all_data.mpu(minKind(4))-.01,'\leftarrow  Jul 1995 ','FontSize',9)
text(maxKind(1)+1,all_data.mpu(maxKind(1))-.01,'\leftarrow  Oct 2008 ','FontSize',10)
text(maxKind(2) - 32, all_data.mpu(maxKind(2)) - .01,'Sep 2008 \rightarrow','FontSize',10)
text(maxKind(3) - 30, all_data.mpu(maxKind(3)) - .01,'Jan 2004 \rightarrow','FontSize',10)

print(gcf, '-dpdf', 'mpuchgfomc_with_labels.pdf');

%return;
